# @Time : 2020/8/31 15:03
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

image = cv.imread("pic/26.png")
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

hist = cv.calcHist([gray], [0], None, [256], [0, 256])

plt.figure()
plt.axis("off")
plt.imshow(cv.cvtColor(gray, cv.COLOR_GRAY2RGB))

plt.figure()
plt.title("Grayscale HIstogram")
plt.xlabel("Bins")
plt.ylabel("# of Pixels")
plt.plot(hist)
plt.xlim([0, 256])

hist /= hist.sum()
plt.figure()
plt.title("Grayscale Histogram (Normalized)")
plt.xlabel("Bins")
plt.ylabel("% of Pixels")
plt.plot(hist)
plt.xlim([0, 256])
plt.show()





















